/*
 * Copyright© 2003-2019 浙江汇信科技有限公司, All Rights Reserved.
 */
package com.icinfo.cloud.provider.punish.ucase.casemain.controller;

import com.icinfo.cloud.provider.common.constant.Constant;
import com.icinfo.cloud.common.core.page.PageResponse;
import com.icinfo.cloud.provider.punish.ucase.casemain.dto.CaseRelatedAppDocumentPageQueryDto;
import com.icinfo.cloud.provider.punish.ucase.casemain.dto.CaseRelatedDocumentDelDto;
import com.icinfo.cloud.provider.punish.ucase.casemain.dto.CaseRelatedDocumentSaveDto;
import com.icinfo.cloud.provider.punish.ucase.casemain.dto.DocumentCatalogQueryDto;
import com.icinfo.cloud.provider.punish.ucase.casemain.service.ICaseRelatedDocumentRecordService;
import com.icinfo.cloud.provider.punish.ucase.casemain.vo.CaseRelatedAppDocumentVo;
import com.icinfo.cloud.provider.punish.ucase.casemain.vo.DocumentCatalogInfoVo;
import com.icinfo.framework.common.web.Result;
import com.icinfo.framework.core.web.BaseController;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 描述: 案件关联文书记录表 case_related_document_record 对应的Controller类.<br>
 *
 * @author framework generator
 * @date 2022年06月17日
 */
@RestController
@RequestMapping("/punish/ucase/related/document")
public class CaseRelatedDocumentRecordController extends BaseController {
    /**
     * 日志记录器
     */
    private static final Logger logger = LoggerFactory.getLogger(CaseRelatedDocumentRecordController.class);

    @Autowired
    private ICaseRelatedDocumentRecordService caseRelatedDocumentRecordService;

    /**
     * 【V1.3.0】描述：获取可关联文书列表
     *
     * @return {@link Result }
     * @author shishengyao
     * @date 2022/06/15
     */
    @PostMapping("/getRelatedDocumentList")
    @ApiOperation(value = "【V1.0.0】描述：获取可关联文书列表", httpMethod = "POST")
    public Result<PageResponse<CaseRelatedAppDocumentVo>> getCanRelatedDocumentList(@RequestBody @Validated CaseRelatedAppDocumentPageQueryDto queryDto) {
        List<CaseRelatedAppDocumentVo> voList = caseRelatedDocumentRecordService.getCanRelatedDocumentListByPartyAndHandle(queryDto);
        return Result.success(Constant.STRING_GET_SUCCESS, new PageResponse<>(voList));
    }

    /**
     * 【V1.3.0】描述：获取文书种类列表
     *
     * @return {@link Result }
     * @author shishengyao
     * @date 2022/06/15
     */
    @PostMapping("/getDocumentCatalogList")
    @ApiOperation(value = "【V1.0.0】描述：获取文书种类列表", httpMethod = "POST")
    public Result<List<DocumentCatalogInfoVo>> getDocumentCatalogList(@RequestBody @Validated DocumentCatalogQueryDto queryDto) {
        List<DocumentCatalogInfoVo> voList = caseRelatedDocumentRecordService.getDocumentCatalogList(queryDto);
        return Result.success(Constant.STRING_GET_SUCCESS, voList);
    }

    /**
     * 【V1.3.0】描述：保存案件关联文书
     *
     * @return {@link Result }
     * @author shishengyao
     * @date 2022/06/15
     */
    @PostMapping("/saveCaseRelatedDocument")
    @ApiOperation(value = "【V1.0.0】描述：保存案件关联文书", httpMethod = "POST")
    public Result<String> saveCaseRelatedDocument(@RequestBody @Validated CaseRelatedDocumentSaveDto saveDto) {
        int count = caseRelatedDocumentRecordService.saveCaseRelatedDocument(saveDto);
        if (count > 0) {
            return Result.success(Constant.STRING_SAVE_SUCCESS);
        }
        return Result.error(Constant.STRING_SAVE_FAIL);
    }

    /**
     * 【V1.4.1】描述：删除案件关联文书
     *
     * @return {@link Result }
     * @author zhangqiang
     * @date 2022/08/28
     */
    @PostMapping("/delCaseRelatedDocument")
    @ApiOperation(value = "【V1.0.0】描述：删除案件关联文书", httpMethod = "POST")
    public Result<String> delCaseRelatedDocument(@RequestBody @Validated CaseRelatedDocumentDelDto delDto) {
        int count = caseRelatedDocumentRecordService.delCaseRelatedDocument(delDto);
        if (count > 0) {
            return Result.success(Constant.STRING_OPERATE_SUCCESS);
        }
        return Result.error(Constant.STRING_OPERATE_FAIL);
    }
}
